/*
 * $Id: PolisGroup.java 27 2007-04-13 01:02:48Z aaron.day $
 */
package org.crazydays.core.data;


import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

/**
 * Polis group class.
 */
@Entity
@SequenceGenerator(name = "POLIS_IDS", sequenceName = "polis_ids", allocationSize = 1)
@Table(name = "polis_group")
public class PolisGroup
	extends PolisData
{
	/** serial version uid */
	public final static long serialVersionUID = "$Id: PolisGroup.java 27 2007-04-13 01:02:48Z aaron.day $".hashCode();

	/** group: Admin */
	public final static String NAME_ADMIN = "Admin";

	/** group: Guest */
	public final static String NAME_GUEST = "Guest";

	/** group: User */
	public final static String NAME_USER = "User";

	/** user */
	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "polis_user")
	protected PolisUser user;

	/** users */
	@ManyToMany(targetEntity = org.crazydays.core.data.PolisUser.class, cascade = {
			CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
	@JoinTable(name = "polis_user_group", joinColumns = { @JoinColumn(name = "polis_group") }, inverseJoinColumns = { @JoinColumn(name = "polis_user") })
	protected Set<PolisUser> users = new HashSet<PolisUser>();

	/** acls */
	@ManyToMany(targetEntity = org.crazydays.core.data.PolisAcl.class, cascade = {
			CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
	@JoinTable(name = "polis_acl_group", joinColumns = { @JoinColumn(name = "polis_group") }, inverseJoinColumns = { @JoinColumn(name = "polis_acl") })
	protected Set<PolisAcl> acls = new HashSet<PolisAcl>();

	/**
	 * Set user.
	 * 
	 * @param user User
	 */
	public void setUser(PolisUser user)
	{
		this.user = user;
	}

	/**
	 * Get user.
	 * 
	 * @return User
	 */
	public PolisUser getUser()
	{
		return user;
	}

	/**
	 * Set users of group.
	 * 
	 * @param users Set of users
	 */
	public void setUsers(Set<PolisUser> users)
	{
		this.users = users;
	}

	/**
	 * Get users of group.
	 * 
	 * @return Set of users
	 */
	public Set<PolisUser> getUsers()
	{
		return users;
	}

	/**
	 * Set acls.
	 * 
	 * @param acls Set of acls
	 */
	public void setAcls(Set<PolisAcl> acls)
	{
		this.acls = acls;
	}

	/**
	 * Get acls.
	 * 
	 * @return Set of acls
	 */
	public Set<PolisAcl> getAcls()
	{
		return acls;
	}
}
